package com.cyx.spring.io.context;

import com.cyx.spring.annotation.Component;
import com.cyx.spring.context.BeanPostProcessor;
import com.cyx.spring.io.test1.A1;
import com.cyx.spring.io.test1.A1Proxy;

import java.util.HashMap;
import java.util.Map;

/**
 * APostProcessor
 *
 * @author yongxiang
 * @date 2024/10/24 10:22
 * @desc
 */

public class APostProcessor implements BeanPostProcessor {

    private Map<String,Object> originBeanMap = new HashMap<>();

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
         if (bean instanceof A1){
             A1Proxy a1Proxy = new A1Proxy((A1) bean);
             originBeanMap.put(beanName,bean);
             return a1Proxy;
         }
         return bean;
    }



    @Override
    public Object postProcessOnSetProperty(Object bean, String beanName) {
        Object o = originBeanMap.get(beanName);
        if (o == null){
            return bean;
        }
        return o;
    }
}
